package ca.ubc.icapture.genapha.actions;

import ca.ubc.icapture.genapha.forms.AnalysisFilesForm;
import ca.ubc.icapture.genapha.forms.FbatBinarizeForm;
import icapture.SQLMgr;
import icapture.beans.DB.Cohort;
import icapture.beans.DB.Phenotypes;
import icapture.beans.Format;
import icapture.genapha.GenotypeToolsManager;

/**
 * Created by IntelliJ IDEA.
 * User: btripp
 * Date: Sep 13, 2006
 * Time: 9:38:59 AM
 * To change this template use File | Settings | File Templates.
 */
public class FbatBinarizeAction extends AnalysisFilesAction
{

    @Override
    protected void processRequest(AnalysisFilesForm form)
    {
        final FbatBinarizeForm fbatForm = (FbatBinarizeForm) form;

        // Add name to the result
        result.setName("Phenotype Binarization");
        SQLMgr.updateResult(result);

        final Phenotypes phenotype = SQLMgr.getPhenotype(Integer.parseInt(fbatForm.getSelectedPhenotype()));
        final Cohort cohort = SQLMgr.getCohort(Integer.parseInt(fbatForm.getSelectedCohort()[0]));
        final GenotypeToolsManager gtm = new GenotypeToolsManager();
        final Format format = gtm.FBAT_FORMAT;
        format.setBinary(true);
        gtm.writeBinarizedPhenotypeLinkageFileFromDB(phenotype, cohort,
                fbatForm.isRemoveMzTwins(), fbatForm.isRemoveDuplicateSubjects(),
                Double.parseDouble(fbatForm.getCutValue()), fbatForm.getCutType(), fbatForm.getSelectedGenes(),
                format, fbatForm.getEmail(), result);
    }
}
